package cn.zebra.dev.other.module.shopAfter.service.impl;

import cn.zebra.dev.ibatis.plus.service.impl.ServiceImpl;
import cn.zebra.dev.ibatis.plus.utils.PageUtils;
import cn.zebra.dev.ibatis.plus.utils.Query;
import cn.zebra.dev.other.module.shopAfter.dao.ShopAfterDao;
import cn.zebra.dev.other.module.shopAfter.entity.ShopAfterEntity;
import cn.zebra.dev.other.module.shopAfter.service.ShopAfterService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 
 *
 * @author runnable
 */
@Service
public class ShopAfterServiceImpl extends ServiceImpl<ShopAfterDao, ShopAfterEntity> implements ShopAfterService {

    @Override
    public PageUtils<ShopAfterEntity> findPageByShopId(Map<String, Object> params) {
        QueryWrapper<ShopAfterEntity> wrapper = new QueryWrapper<>();
        wrapper.select("user_id, order_id, info , state, solution, create_time,type");
        if(params.get("state") != null){
            wrapper.apply(params.containsKey("state"),"state={0}",params.get("state"));
        }
        wrapper.apply("shop_id={0}",params.get("shopId"));
        IPage<ShopAfterEntity> page = this.page(
                new Query<ShopAfterEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    @Override
    public PageUtils<ShopAfterEntity> findPageByUserId(Map<String, Object> params) {

        QueryWrapper<ShopAfterEntity> wrapper = new QueryWrapper<>();
        wrapper.select("user_id, order_id, info , state, solution, create_time,type");
        if(params.get("state") != null){
            wrapper.apply(params.containsKey("state"),"state={0}",params.get("state"));
        }
        wrapper.apply("user_id={0}",params.get("userId"));
        IPage<ShopAfterEntity> page = this.page(
                new Query<ShopAfterEntity>(params).getPage(),
                wrapper
        );

        return new PageUtils<>(page);
    }

    @Override
    public List<ShopAfterEntity> findByIds(List<Long> shopAfterIds) {
        QueryWrapper<ShopAfterEntity> wrapper = new QueryWrapper<>();
        wrapper.in("id", shopAfterIds);
        return list(wrapper);
    }

}
